<script>
	// #ifndef VUE3
	export default {
		onLaunch: function() {
			console.log('App Launch')
			// 初始化全局数据
			if (!this.$options.globalData) {
				this.$options.globalData = {}
			}
			// 设置自定义导航栏高度
			this.setNavBarInfo()
		},
		onShow: function() {
			console.log('App Show')
		},
		onHide: function() {
			console.log('App Hide')
		},
		methods: {
			// 计算导航栏相关尺寸
			setNavBarInfo() {
				try {
					// 获取系统信息
					const systemInfo = uni.getSystemInfoSync()
					// 状态栏高度
					this.statusBarHeight = systemInfo.statusBarHeight
					// 胶囊按钮位置信息
					const menuButtonInfo = uni.getMenuButtonBoundingClientRect()
					// 导航栏高度 = 状态栏高度 + 44
					this.navBarHeight = this.statusBarHeight + 44
					
					// 保存到全局数据
					getApp().globalData = {
						...getApp().globalData,
						statusBarHeight: this.statusBarHeight,
						navBarHeight: this.navBarHeight,
						menuButtonInfo: menuButtonInfo
					}
				} catch (e) {
					console.error('设置导航栏信息失败', e)
				}
			}
		},
		globalData: {
			statusBarHeight: 0,
			navBarHeight: 0,
			activeTabIndex: 0, // 默认选中第一个tab（智问莒县）
			tabList: [
				{ name: '智问莒县', icon: 'chat', pagePath: 'pages/zhixun/index' },
				{ name: '时空对话', icon: 'calendar', pagePath: 'pages/shikong/index' },
				{ name: '传图讲解', icon: 'image', pagePath: 'pages/tujie/index' },
				{ name: '打卡有礼', icon: 'location', pagePath: 'pages/daka/index' },
				{ name: '游记生成', icon: 'compose', pagePath: 'pages/youji/index' }
			]
		}
	}
	// #endif

	// #ifdef VUE3
	export default {
		globalData: {
			statusBarHeight: 0,
			navBarHeight: 0,
			activeTabIndex: 0,
			tabList: [
				{ name: '智问莒县', icon: 'chat', pagePath: 'pages/zhixun/index' },
				{ name: '时空对话', icon: 'calendar', pagePath: 'pages/shikong/index' },
				{ name: '传图讲解', icon: 'image', pagePath: 'pages/tujie/index' },
				{ name: '打卡有礼', icon: 'location', pagePath: 'pages/daka/index' },
				{ name: '游记生成', icon: 'compose', pagePath: 'pages/youji/index' }
			]
		},
		onLaunch: function() {
			console.log('App Launch')
			this.setNavBarInfo()
		},
		onShow: function() {
			console.log('App Show')
		},
		onHide: function() {
			console.log('App Hide')
		},
		methods: {
			setNavBarInfo() {
				try {
					const systemInfo = uni.getSystemInfoSync()
					this.globalData.statusBarHeight = systemInfo.statusBarHeight
					const menuButtonInfo = uni.getMenuButtonBoundingClientRect()
					this.globalData.navBarHeight = this.globalData.statusBarHeight + 44
					this.globalData.menuButtonInfo = menuButtonInfo
				} catch (e) {
					console.error('设置导航栏信息失败', e)
				}
			}
		}
	}
	// #endif
</script>

<style>
	/*每个页面公共css */
	page {
		font-size: 14px;
		color: #333;
		background-color: #f6f6f6;
		font-family: -apple-system, BlinkMacSystemFont, 'Helvetica Neue', Helvetica, Segoe UI, Arial, Roboto, 'PingFang SC', 'miui', 'Hiragino Sans GB', 'Microsoft Yahei', sans-serif;
	}
	
	/* 去掉button的默认样式 */
	button {
		background-color: transparent;
		margin: 0;
		padding: 0;
		line-height: normal;
		border-radius: 0;
	}
	
	button::after {
		border: none;
	}
	
	/* 自定义TabBar样式 */
	.custom-tab-bar {
		position: fixed;
		bottom: 0;
		left: 0;
		right: 0;
		height: 50px;
		background-color: #fff;
		display: flex;
		box-shadow: 0 -1px 5px rgba(0, 0, 0, 0.1);
		z-index: 999;
	}
	
	.tab-item {
		flex: 1;
		display: flex;
		flex-direction: column;
		align-items: center;
		justify-content: center;
		font-size: 10px;
		transition: all 0.2s;
	}
	
	.tab-icon {
		width: 24px;
		height: 24px;
		margin-bottom: 2px;
	}
	
	.tab-text {
		color: #999;
	}
	
	.tab-active .tab-text {
		color: #007aff;
	}
	
	/* 兼容底部安全区域 */
	.safe-area-inset-bottom {
		padding-bottom: constant(safe-area-inset-bottom); /* iOS 11.0 */
		padding-bottom: env(safe-area-inset-bottom); /* iOS 11.2+ */
	}
</style>
